package com.example.demo.paypal;

import com.paypal.api.payments.Agreement;
import com.paypal.base.rest.APIContext;
import com.paypal.base.rest.PayPalRESTException;

/**
 * Created with IntelliJ IDEA.
 *  真正扣费的API
 * @Author: anlu
 * @Date: 2021/07/20
 * @Description:
 */
public class CapturesRenewalPlanOrder {
    private static String clientId = "AcZ2pVjVhgmcL4oaaVlrMtFcYGcYnoGdD-molKMuCSXaV6xZraDqxIFYisZ-1vO8ZlyIPDbNAKtutCnU";
    private static String clientSecret = "ELZSlONq3xB6NB6iDLnOPwsEVv0ZrFRHrTxR_JxUtml1gCHmn3uozul0LG0gDXfWrozdBUM5zhcRyP6z";
    private static String mode = "sandbox";

    @SuppressWarnings("static-access")
    public String captureOrder(String token) {
        APIContext context = new APIContext(clientId, clientSecret, mode);
        //用户支付成功后，重定向返回的页面携带的token
        Agreement agreement =  new Agreement();
        agreement.setToken(token);

        try {
            Agreement activeAgreement = agreement.execute(context, agreement.getToken());
            System.out.println("Agreement created with ID " + activeAgreement.getId());
        } catch (PayPalRESTException e) {
            System.err.println(e.getDetails());
        }
        return null;
    }
    public static void main(String[] args) {
        new CapturesRenewalPlanOrder().captureOrder("EC-7DR56502PU7156539");
    }

}
